package com.qingcloud.adminbackend.controller;

import com.qingcloud.adminbackend.base.AjaxResult;
import com.qingcloud.adminbackend.entity.aline.TcpValueCommandDTO;
import com.qingcloud.adminbackend.entity.upgrade.*;
import com.qingcloud.adminbackend.entity.upgrade.*;
import com.qingcloud.adminbackend.service.impl.ITdCalibrationServiceImpl;
import com.qingcloud.adminbackend.utils.CookieUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName TdCalibrationController
 * @Description 设备校准api
 * @Author qym
 * @Date 2020/12/22 下午12:47
 **/
@Api(value = "设备校准", description = "设备校准")
@RestController
@RequestMapping("/calibrationEquipment")
public class TdCalibrationController {

    @Resource
    private ITdCalibrationServiceImpl tdCalibrationService;

    /**
     * 分页查询
     *
     * @param calibrationRequest
     * @return
     */
    @ApiOperation(value = "分页查询校准事件列表", notes = "分页查询校准事件列表", response = CalibrationEventDTO.class)
    @PostMapping(value = "/calibrationEventPage")
    public AjaxResult getCalibrationEventPage(@RequestBody CalibrationRequest calibrationRequest) {
        return tdCalibrationService.getCalibrationEventPage(calibrationRequest);
    }

    /**
     * 查询设备详情
     *
     * @param equipmentIds
     * @return
     */
    @ApiOperation(value = "查询设备详情", notes = "查询设备详情", response = CalibrationEquipmentDetailDTO.class)
    @PostMapping(value = "/searchEquipments")
    public AjaxResult searchEquipments(@RequestBody List<String> equipmentIds) {
        return tdCalibrationService.searchEquipments(equipmentIds);
    }

    /**
     * 新增校准事件
     *
     * @param calibrationEventDTO
     * @return
     */
    @ApiOperation(value = "新增校准事件", notes = "新增校准事件")
    @PostMapping(value = "/addCalibrationEvent")
    public AjaxResult addCalibrationEvent(@RequestBody CalibrationEventDTO calibrationEventDTO, HttpServletRequest request) {
        String userId = CookieUtil.getUserId(request);
        calibrationEventDTO.setCalibrationUser(userId);
        return tdCalibrationService.addCalibrationEvent(calibrationEventDTO);
    }

    /**
     * 新增被校准设备
     *
     * @param calibrationEquipmentDTOs
     * @return
     */
    @ApiOperation(value = "新增被校准设备", notes = "新增被校准设备")
    @PostMapping(value = "/addCalibrationEquipment")
    public AjaxResult addCalibrationEquipment(@RequestBody List<CalibrationEquipmentDTO> calibrationEquipmentDTOs) {
        return tdCalibrationService.addCalibrationEquipment(calibrationEquipmentDTOs);
    }

    /**
     * 查询设备校准模式34
     *
     * @param equipmentIds
     * @return
     */
    @ApiOperation(value = "查询设备校准模式", notes = "查询设备校准模式", response = CalibrationEquipmentDetailDTO.class)
    @PostMapping(value = "/searchCalibrationMode")
    public AjaxResult searchCalibrationMode(@RequestBody List<String> equipmentIds) {
        return tdCalibrationService.searchCalibrationMode(equipmentIds);
    }

    /**
     * 设置设备校准模式34
     *
     * @param tcpValueCommandDTOList
     * @return
     */
    @ApiOperation(value = "设置设备校准模式", notes = "设置设备校准模式")
    @PostMapping(value = "/setCalibrationMode")
    public AjaxResult setCalibrationMode(@RequestBody List<TcpValueCommandDTO> tcpValueCommandDTOList) {
        return tdCalibrationService.setCalibrationMode(tcpValueCommandDTOList);
    }

    /**
     * 查询设备防拆32
     *
     * @param equipmentIds
     * @return
     */
    @ApiOperation(value = "查询设备防拆", notes = "查询设备防拆", response = CalibrationEquipmentDetailDTO.class)
    @PostMapping(value = "/searchCalibrationTamper")
    public AjaxResult searchCalibrationTamper(List<String> equipmentIds) {
        return tdCalibrationService.searchCalibrationTamper(equipmentIds);
    }

    /**
     * 设置设备防拆32
     *
     * @param tcpValueCommandDTOList
     * @return
     */
    @ApiOperation(value = "设置设备防拆", notes = "设置设备防拆")
    @PostMapping(value = "/setCalibrationTamper")
    public AjaxResult setCalibrationTamper(List<TcpValueCommandDTO> tcpValueCommandDTOList) {
        return tdCalibrationService.setCalibrationTamper(tcpValueCommandDTOList);
    }

    /**
     * 设置设备校准步长
     *
     * @param calibrationStepDTO
     * @return
     */
    @ApiOperation(value = "设置设备校准步长", notes = "设置设备校准步长")
    @PostMapping(value = "/setCalibrationStep")
    public AjaxResult setCalibrationStep(@RequestBody CalibrationStepDTO calibrationStepDTO) {
        return tdCalibrationService.setCalibrationStep(calibrationStepDTO);
    }

    /**
     * 查询设备校准步长35
     *
     * @param equipmentIds
     * @return
     */
    @ApiOperation(value = "查询设备校准步长", notes = "查询设备校准步长", response = CalibrationStepDTO.class)
    @PostMapping(value = "/searchCalibrationStep")
    public AjaxResult searchCalibrationStep(@RequestBody List<String> equipmentIds) {
        return tdCalibrationService.searchCalibrationStep(equipmentIds);
    }

    /**
     * 获取最新数据
     *
     * @param equipmentIds
     * @return
     */
    @ApiOperation(value = "获取最新数据", notes = "获取最新数据", response = CalibrationEquipmentDataDTO.class)
    @GetMapping(value = "/getNewestData")
    public AjaxResult getNewestData(@RequestParam("equipmentIds") List<String> equipmentIds) {
        return tdCalibrationService.getNewestData(equipmentIds);
    }

    /**
     * 查询设备dac
     *
     * @param equipmentId
     * @return
     */
    @ApiOperation(value = "查询设备dac", notes = "查询设备dac", response = CalibrationEquipmentDetailDTO.class)
    @GetMapping(value = "/searchCalibrationDAC")
    public AjaxResult searchCalibrationDAC(@RequestParam("equipmentId") String equipmentId) {
        return tdCalibrationService.searchCalibrationDAC(equipmentId);
    }

    /**
     * 设置校准精度36
     *
     * @param calibrationAccuracyDTO
     * @return
     */
    @ApiOperation(value = "设置校准精度", notes = "设置校准精度")
    @PostMapping(value = "/setCalibrationAccuracy")
    public AjaxResult setCalibrationAccuracy(@RequestBody CalibrationAccuracyDTO calibrationAccuracyDTO) {
        return tdCalibrationService.setCalibrationAccuracy(calibrationAccuracyDTO);
    }

    /**
     * 查询设备校准精度36
     *
     * @param equipmentIds
     * @return
     */
    @ApiOperation(value = "查询设备校准精度", notes = "查询设备校准精度", response = CalibrationAccuracyDTO.class)
    @PostMapping(value = "/searchCalibrationAccuracy")
    public AjaxResult searchCalibrationAccuracy(@RequestBody List<String> equipmentIds) {
        return tdCalibrationService.searchCalibrationAccuracy(equipmentIds);
    }

    /**
     * 停止校准
     *
     * @param equipmentIds
     * @return
     */
    @ApiOperation(value = "停止校准", notes = "停止校准")
    @PostMapping(value = "/stopCalibration")
    public AjaxResult stopCalibration(@RequestBody List<String> equipmentIds) {
        return tdCalibrationService.stopCalibration(equipmentIds);
    }

    /**
     * 全部停止校准
     *
     * @param eventIds
     * @return
     */
    @ApiOperation(value = "停止校准", notes = "停止校准")
    @GetMapping(value = "/stopAllCalibration")
    public AjaxResult stopAllCalibration(@RequestParam("eventIds") List<Integer> eventIds) {
        return tdCalibrationService.stopAllCalibration(eventIds);
    }

    /**
     * 开始校准
     *
     * @param equipmentIds
     * @return
     */
    @ApiOperation(value = "开始校准", notes = "开始校准")
    @PostMapping(value = "/startCalibration")
    public AjaxResult startCalibration(@RequestBody List<String> equipmentIds) {
        return tdCalibrationService.startCalibration(equipmentIds);
    }

    /**
     * 设置上传周期
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "设置上传周期", notes = "设置上传周期")
    @PostMapping(value = "/setAllUpLoadFeq")
    public AjaxResult setAllUpLoadFeq(@RequestBody CalibrationRequest request) {
        return tdCalibrationService.setAllUpLoadFeq(request);
    }
}
